|
|
|
|
|
|
|
db.Close
Set db = Nothing
Set db = ws.OpenDatabase(strGlobalDBName, False, False, strConnect)
End Select
GoTo SQlDoCommandExit ' exit routine
'
' local error handler
SQLDoCommandErr:
ErrMsg Err, Error$, intLine, strLine, "SQLDoCommand"
On Error Resume Next
ws.Rollback
InitApp
'
' routine exit
SQlDoCommandExit:
'
End Sub |
|
|
|
|
|
|
|
|
Even though it looks as though several things take place in this routine, only three tasks are being handled by SQLDoCommand. First, you get the first word in the script line, and then you have to make a couple of decisions on how to properly execute the SQL statement. |
|
|
|
|
|
|
|
|
If the first word is DELETE, DROP, or ALTER, you turn off the local error handler. This is done for convenience. You want to be able to create scripts that can use the SQL words DELETE, DROP, and ALTER to remove table objects from the database. Because the objects may not exist, you could get errors that can halt the script processing. To make life simple, SQL-VB5 ignores these errors. Once you write a few SQL-VB5 scripts, you'll appreciate this feature. |
|
|
|
|
|
|
|
|
Next, you have to check for the SQL keywords that can return result sets. These are TRANSFORM and SELECT. These keywords should be handled differently from SQL statements that do not return result sets. If you see TRANSFORM, you call the ShowTable routine to load and display the SQLVBChild child form on the screen. If you see SELECT, you make one additional check. If the line contains the INTO keyword, you have an SQL statement that creates a new table. Using the INTO keyword means that the SELECT statement does not return a result set. If there is no INTO in the SQL statement, you hand the statement off to the ShowTable routine. If the line starts with any other SQL keyword, you simply execute the command using the Visual Basic Execute method on the database. |
|
|
|
|
|
|
|
|
The SQLDoCommand routine calls the ShowTable routine, so you need to add that routine to the project. This is a simple routine that updates some variables, creates a new instance of the SQLVBChild child form, and shows the new form. Create a Public Sub called ShowTable and enter the code in Listing A.23. |
|
|
|
|
|